package com.ruoyi.web.controller.wq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqTuan;
import com.ruoyi.wq.domain.WqUserTuan;
import com.ruoyi.wq.domain.vo.WqUserTuanVO;
import com.ruoyi.wq.service.IWqUserTuanService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 我的拼团Controller
 * 
 * @author ruoyi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/wq/userTuan")
public class WqUserTuanController extends BaseController {

    @Autowired
    private IWqUserTuanService wqUserTuanService;

    /**
     * 查询团购列表
     */
    @Anonymous
    @GetMapping("/getList")
    public AjaxResult getList(WqTuan wqTuan){
        return AjaxResult.success(wqUserTuanService.getListByPage(wqTuan));
    }

    /**
     * 导出我的拼团列表
     */
    @PreAuthorize("@ss.hasPermi('wq:userTuan:export')")
    @Log(title = "我的拼团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WqUserTuan wqUserTuan)
    {
        List<WqUserTuan> list = wqUserTuanService.selectWqUserTuanList(wqUserTuan);
        ExcelUtil<WqUserTuan> util = new ExcelUtil<WqUserTuan>(WqUserTuan.class);
        util.exportExcel(response, list, "我的拼团数据");
    }

    /**
     * 获取我的拼团详细信息
     */
    @PreAuthorize("@ss.hasPermi('wq:userTuan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wqUserTuanService.selectWqUserTuanById(id));
    }

    /**
     * 新增我的拼团
     */
    @PreAuthorize("@ss.hasPermi('wq:userTuan:add')")
    @Log(title = "我的拼团", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WqUserTuan wqUserTuan)
    {
        return toAjax(wqUserTuanService.insertWqUserTuan(wqUserTuan));
    }

    /**
     * 修改我的拼团
     */
    @PreAuthorize("@ss.hasPermi('wq:userTuan:edit')")
    @Log(title = "我的拼团", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WqUserTuan wqUserTuan)
    {
        return toAjax(wqUserTuanService.updateWqUserTuan(wqUserTuan));
    }

    /**
     * 删除我的拼团
     */
    @PreAuthorize("@ss.hasPermi('wq:userTuan:remove')")
    @Log(title = "我的拼团", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wqUserTuanService.deleteWqUserTuanByIds(ids));
    }
}
